home *** CD-ROM | disk | FTP | other *** search
/ The Utilities Experience / The Utilities Experience - Volume 1.iso / software / disk_tools / cd32goodies / cdaudio.c < prev    next >
C/C++ Source or Header  |  1978-06-29  |  3KB  |  131 lines

  1. /*
  2.  
  3.     written by Daniel Balster, dbalster@uni-paderborn.de
  4. */
  5.  
  6. #include <exec/exec.h>
  7. #include <dos/dos.h>
  8. #include <devices/cd.h>
  9. #include <proto/exec.h>
  10. #include <proto/dos.h>
  11.  
  12. #define TEMPLATE "PAUSE/S,PLAY/S,TRACK/N/K,LENGTH/N/K,FADE/N/K,VOLUME/N/K,MOTOR/N/K,SEARCH/N/K"
  13.  
  14. /*
  15.     PAUSE    -> drive is in PAUSE mode (laser beam locks)
  16.     
  17.     PLAY    -> drive is in PLAY mode (laser beam unlocks)
  18.  
  19.     TRACK    -> track to play. default is first track
  20.     
  21.     LENGTH    -> how many tracks to play. default is 1000 tracks (only used in conjunction with TRACK)
  22.     
  23.     FADE    -> duration of volume fade. default is 0 (only used in conjunction with VOLUME)
  24.     
  25.     VOLUME    -> volume from 0..16383. default is maximum volume. <2048 == mute audio
  26.     
  27.     MOTOR    -> 0 to stop drive motor, 1 to restart drive motor.
  28.     
  29.     SEARCH    -> play mode: 0 is normal mode (default), 1 is fast forward and 2 is fast reverse mode
  30.  
  31. */
  32.  
  33. struct {
  34.     ULONG    pause,play,track,length,fade,volume,motor,search;
  35.     BOOL    quiet;
  36.     ULONG    pads[7];
  37. } args = {0};
  38.  
  39. void pause (struct IOStdReq *ior, int pausemode)
  40. {
  41.     ior->io_Command    = CD_PAUSE;
  42.     ior->io_Data    = NULL;
  43.     ior->io_Length    = pausemode;
  44.     ior->io_Offset    = 0;
  45.     DoIO(ior);
  46. }
  47.  
  48. void motor (struct IOStdReq *ior, int state)
  49. {
  50.     ior->io_Command    = CD_MOTOR;
  51.     ior->io_Data    = NULL;
  52.     ior->io_Length    = state;
  53.     ior->io_Offset    = 0;
  54.     DoIO(ior);
  55. }
  56.  
  57. void playtrack (struct IOStdReq *ior, int numtracks, int firsttrack)
  58. {
  59.     ior->io_Command    = CD_PLAYTRACK;
  60.     ior->io_Data    = NULL;
  61.     ior->io_Length    = numtracks;
  62.     ior->io_Offset    = firsttrack;
  63.     SendIO(ior);
  64. }
  65.  
  66. void playmode (struct IOStdReq *ior, int playmode)
  67. {
  68.     ior->io_Command    = CD_SEARCH;
  69.     ior->io_Data    = NULL;
  70.     ior->io_Length    = playmode;
  71.     ior->io_Offset    = 0;
  72.     DoIO(ior);
  73. }
  74.  
  75. void attenuate (struct IOStdReq *ior, int duration, int volume)
  76. {
  77.     ior->io_Command    = CD_ATTENUATE;
  78.     ior->io_Data    = NULL;
  79.     ior->io_Length    = duration;
  80.     ior->io_Offset    = volume;
  81.     DoIO(ior);
  82. }
  83.  
  84. int main (void)
  85. {
  86.     struct RDArgs *rdargs;
  87.     struct MsgPort *mp;
  88.     struct IOStdReq *ior;
  89.     int length=1, fade=0;
  90.     
  91.     if (rdargs=ReadArgs(TEMPLATE,(LONG*)&(args),NULL))
  92.     {
  93.         if(!args.quiet) PutStr("*** CD Audio v1.0.0 *** by Daniel Balster\n");
  94.  
  95.         if(mp=CreateMsgPort())
  96.         {
  97.             if(ior=(struct IOStdReq*)CreateIORequest(mp,sizeof(struct IOStdReq)))
  98.             {
  99.                 if(!OpenDevice("cd.device",0,ior,0))
  100.                 {
  101.                     if (args.pause)    pause(ior,1);
  102.                     if (args.play)    pause(ior,0);
  103.                     
  104.                     if (args.length) length = *(ULONG*)args.length;
  105.                     if (args.track) playtrack(ior,length,*(ULONG*)args.track);
  106.             
  107.                     if (args.fade) fade = *(ULONG*)args.fade;
  108.                     if (args.volume) attenuate(ior,fade,*(ULONG*)args.volume);
  109.  
  110.                     if (args.motor) motor(ior,*(ULONG*)args.motor);
  111.  
  112.                     if (args.search) playmode(ior,*(ULONG*)args.search);
  113.  
  114.                     CloseDevice((struct IORequest*)ior);
  115.                 }
  116.                 else PutStr("cannot access cd.device?\n");
  117.                 
  118.                 DeleteIORequest((struct IORequest*)ior);
  119.             }
  120.             else PutStr("cannot create ioreq?\n");
  121.  
  122.             DeleteMsgPort(mp);
  123.         }
  124.         else PutStr("cannot create msgport?\n");
  125.  
  126.         FreeArgs(rdargs);
  127.     }
  128.     else PrintFault(IoErr(),0);
  129.  
  130.     return RETURN_OK;
  131. }